package net.myspring.middle.mapper;

import net.myspring.common.mybatis.domain.Page;
import net.myspring.common.mybatis.domain.Pageable;
import net.myspring.common.mybatis.provider.mapper.CrudMapper;
import net.myspring.middle.domain.Menu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;

import java.util.List;
import java.util.Map;

/**
 * Created by liuj on 16/7/10.
 */
@Mapper
public interface MenuMapper extends CrudMapper<Menu,String> {

    List<Menu> findByIds(List<String> ids);

    List<Menu> findByParentId(String id);

    Menu findByName(String name);

    Menu findByLink(String link);

    Page<Menu> findPage(Pageable pageable, @Param("p") Map<String, Object> map);

    List<Menu> findAll();

    List<Menu> findByTypes(@Param("types") List<Integer> types);

    @Cacheable(value = "codeMenus", key = "#p0")
    Menu findByCode(String code);

    @Caching(
            evict = {
                    @CacheEvict(value = "menus", key = "#p0.id"),
                    @CacheEvict(value = "codeMenus", key = "#p0.code")
            }
    )
    int update(Menu menu);

    @Cacheable(value = "menus", key = "#p0")
    Menu findOne(String id);
}
